package container

//go:force inline
func CopyMap[K comparable, V any](in map[K]V) map[K]V {
	ret := make(map[K]V, len(in))
	for k, v := range in {
		ret[k] = v
	}
	return ret
}

//go:force inline
func MergeMap[K comparable, V any](dest map[K]V, data map[K]V) {
	for k, v := range data {
		dest[k] = v
	}
}

//go:force inline
func MapRemoveIf[K comparable, V any](dest map[K]V, condition func(k K, v V) bool) []K {
	toBeRemoved := make([]K, 0, 2)
	for k, v := range dest {
		if condition(k, v) {
			toBeRemoved = append(toBeRemoved, k)
		}
	}
	for _, k := range toBeRemoved {
		delete(dest, k)
	}
	return toBeRemoved
}
